/**
* @Author: zmx
* @Date: 2023/9/26
* @Description:
*/
<template>
  <el-dialog :title="title==='新增'?'新建一类作业项':title+'一类作业项'" :visible.sync="show" append-to-body width="30%" :before-close="cancel">
    <el-form :inline="true" :model="formInline">
      <el-form-item label="作业项名称：">
        <el-input v-model="formInline.assignName" placeholder="请输入作业项名称"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="checkBtn">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {userApi} from '../../api/inspection/apiUntil'
export default {
  props: ['DialogComponentShow','title','row'],
  data() {
    return {
      show: false, //弹窗默认隐藏
      currentRow: null, //选择的行数据
      formInline: {
        assignName: '',
      },
    };
  },
  mounted() {
    //显示弹窗
    this.show = this.DialogComponentShow
    if(this.title==='修改'){
     this.formInline.assignName = this.row.assignName
    }
  },
  methods: {
    cancel(){
      this.show = false
      this.$parent.cancel()
    },
    //关闭弹窗
    handleClose() {
      this.show = false
      this.$emit('closeDialog')
    },
    getResult(res){
      if(res.code===200){
        this.$message({
          message: this.title+'成功',
          type: 'success'
        });
        this.handleClose()
      }
    },
    checkBtn() {
      let param = {
        "assignName":this.formInline.assignName,
      }
      if(this.title==='新增'){
        userApi.getAssignAdd(param).then((res)=>{
          this.getResult(res)
        })
      }else {
        userApi.getAssignUpt({id:this.row.id,...param}).then((res)=>{
          this.getResult(res)
        })
      }
    }
  }
};
</script>

<style lang="scss" scoped>
>>> .el-dialog__header{
  padding: 20px !important;
  background: #1B7B87;
}
>>> .el-dialog__title{
  color: #fff !important;
  font-size: 16px;
}
</style>
